<%--                                                                       --%>
<%-- Copyright (c) 2004 BroadVision, Inc.  All rights reserved.            --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>

<%
  String ctxPath = request.getContextPath();
%>

<script language="javascript">

function doCreateEntityPreference(form){
  var action = '<c:url value="/ep/portletEntityPreferenceNew.do"/>';
  if (action.indexOf("?") == -1) {
    action += "?";
  }
  action += "programId=" + document.portletEntityPreferenceListForm.programId.value;

  document.portletEntityPreferenceListForm.action = action;
  document.portletEntityPreferenceListForm.submit();
}

function doPortletEditEntityPreference(preferenceName){
  var action = '<c:url value="/ep/portletEntityPreferenceEdit.do"/>';
  if (action.indexOf("?") == -1) {
    action += "?";
  }
  action += "programId=" + document.portletEntityPreferenceListForm.programId.value;
  action += "&preferenceName=" + preferenceName;
  
  document.portletEntityPreferenceListForm.action = action;
  document.portletEntityPreferenceListForm.submit();
}

function doPortletDeleteEntityPreference(preferenceName) {
  if (confirm('<bean:message key="ep.portlet.alert.confirmDeletePortletEntityPreference" bundle="ep.messages"/>')) {
    var action = '<c:url value="/ep/portletEntityPreferenceDelete.do"/>';
    if(action.indexOf("?") == -1) {
      action += "?";
    }
    action += "programId=" + document.portletEntityPreferenceListForm.programId.value;
    action += "&preferenceName=" + preferenceName;
  
    document.portletEntityPreferenceListForm.action = action;
    document.portletEntityPreferenceListForm.submit();
  }
}

<%@ include file="/mc/common/jsutils.jsp" %>
</script>

<c:set var="editImg">
<img src="<%= ctxPath %>/ep/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.edit" bundle="ep.messages"/>" title="<bean:message key="image.alt.edit" bundle="ep.messages"/>">
</c:set>
<c:set var="offlineImg">
<img src="<%= ctxPath %>/ep/images/action/icon_offline.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.setOffline" bundle="ep.messages"/>" title="<bean:message key="image.alt.setOffline" bundle="ep.messages"/>">
</c:set>
<c:set var="onlineImg">
<img src="<%= ctxPath %>/ep/images/action/icon_online.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.setOnline" bundle="ep.messages"/>" title="<bean:message key="image.alt.setOnline" bundle="ep.messages"/>">
</c:set>
<c:set var="deleteImg">
<img src="<%= ctxPath %>/ep/images/action/icon_delete.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.delete" bundle="ep.messages"/>" title="<bean:message key="image.alt.delete" bundle="ep.messages"/>">
</c:set>
<c:set var="portletAppId">
<%= request.getParameter("portletAppId") %>
</c:set>
<c:set var="portletId">
<%= request.getParameter("portletId") %>
</c:set>
<c:set var="serverId">
<%= request.getParameter("serverId") %>
</c:set>
<c:set var="programId">
<%= request.getParameter("programId") %>
</c:set>
<%
  java.util.HashMap map = new java.util.HashMap();
  String pId = request.getParameter("programId");
  map.put("programId",pId);
  pageContext.setAttribute("pagetabParam",map);
%>

<form name="portletEntityPreferenceListForm" method="post">
<input type="hidden" name="portletEntityId" value=""/>
<input type="hidden" name="portletAppId" value="<c:out value="${portletAppId}"/>"/>
<input type="hidden" name="portletId" value="<c:out value="${portletId}"/>"/>
<input type="hidden" name="serverId" value="<c:out value="${serverId}"/>"/>
<input type="hidden" name="programId" value="<c:out value="${programId}"/>"/>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
      <bean-el:message key="ep.portlet.entity.edit.page.title" bundle="ep.messages" arg0="${epPortletEntityForm.map.name}"/>
      </div>
      <div class="errorMessage"><html:errors bundle="ep.messages"/></div>
      <div>
      <%@include file="/mc/common/pagetab.jsp" %>
      </div>

      <div class="pageSubtitle">
        <span class="left"><bean:message key="ep.portlet.entity.preferences" bundle="ep.messages"/></span>
        <span class="right"><input type="button" class="inputButton" value="<bean:message key="button.new.preference" bundle="ep.messages"/>" onclick="doCreateEntityPreference(this.form)"></span>
      </div>

<logic:notEmpty name="list">
      <div class="globalButtonWrap">
        <input type="button" name="selectAllPreferences" class="globalButton" 
          onclick="check(this.form.preferenceNames, this);" value="<bean:message key="button.selectAll" bundle="ep.messages"/>">
        <input type="button" name="deletePreferences" class="globalButton" 
          onclick="if (isAnyChecked(this.form.preferenceNames, '<bean:message key="ep.portlet.alert.atLeastOnePreference" bundle="ep.messages"/>', '<bean:message key="ep.portlet.alert.confirmDeletePortletEntityPreference" bundle="ep.messages"/>')) doAction('/ep/portletEntityPreferenceDelete.do', this.form);"
          value='<bean:message key="button.delete" bundle="ep.messages"/>'>
      </div>
</logic:notEmpty>

      <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Search result table" width="100%">
        <tr class="listHeader">
          <th id="Checkboxes">&nbsp;</th>
          <th id="Name" align="left"><bean:message key="ep.header.name.portlet.entity.preference" bundle="ep.messages"/></th>
          <th id="Editable" align="left"><bean:message key="ep.header.name.portlet.entity.preference.editable" bundle="ep.messages"/></th>
          <th id="Value" align="left"><bean:message key="ep.header.name.portlet.entity.preference.value" bundle="ep.messages"/></th>
          <th id="Actions" align="left" nowrap><bean:message key="ep.header.actions" bundle="ep.messages"/></th>
        </tr>

        <!-- results -->

<logic:iterate id="item" name="list" indexId="index">
        <tr class="<%= index.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">
          <td headers="Checkboxes" align="center"><input type="checkbox" name="preferenceNames" value="<c:out value="${item.map.name}"/>"/></td>
          <td headers="Name"><bean:write name="item" property="name"/></td>
          <td headers="Editable">
          <c:choose>
            <c:when test="${item.map.editable == true}">
              <bean:message key="ep.yes" bundle="ep.messages"/>
            </c:when>
            <c:otherwise>
              <bean:message key="ep.no" bundle="ep.messages"/>
            </c:otherwise>
          </c:choose>
          </td>
          <td headers="Value">
          <c:choose>
            <c:when test="${item.map.valueList != null}">
              <bean:size id="pvsize" name="item" property="valueList"/>
              <logic:iterate id="pvalue" name="item" property="valueList" indexId="valIndex">
                 <bean:write name="pvalue"/><c:if test="${pvsize > valIndex + 1}">,</c:if>
              </logic:iterate>
            </c:when>
          </c:choose>
          <td headers="Actions">           
            <a href="#" onclick="doPortletEditEntityPreference('<c:out value="${item.map.name}"/>');"><c:out
               value='${editImg}' escapeXml="false"/></a>             
            <a href="#" onclick="doPortletDeleteEntityPreference('<c:out value="${item.map.name}"/>');"><c:out
            value='${deleteImg}' escapeXml="false"/></a>
          </td>
        </tr>
</logic:iterate>

      </table>

      <!-- pagination -->
<%@ include file="/mc/common/pager.jsp" %>

    </td>
  </tr>
</table>
</form>
